﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.SessionState;
//using QIMSServer.Service;

namespace MaxStudio.Concrete.DBUtility
{
    class PermissionModule : IHttpModule
    {
                public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += new EventHandler(this.Application_PreRequest);
        }

        public void Dispose()
        {
        }

        public void Application_PreRequest(Object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            
            HttpRequest request = application.Request;

            String lang = ConcreteConstants.LANG_ZHCN; ;
            if (request.Cookies[ConcreteConstants.CURRENT_LANGUAGE] != null &&
                request.Cookies[ConcreteConstants.CURRENT_LANGUAGE].Value != "")
                lang = request.Cookies[ConcreteConstants.CURRENT_LANGUAGE].Value;

            CultureInfo defaultDateTimeFormat = new CultureInfo(ConcreteConstants.LANG_ENUS);
                CultureInfo currentInfo = null;
                try
                {
                    currentInfo = new CultureInfo(lang);
                    currentInfo.DateTimeFormat = defaultDateTimeFormat.DateTimeFormat;
                }
                catch
                {
                    currentInfo = new CultureInfo(ConcreteConstants.LANG_ZHCN);
                    currentInfo.DateTimeFormat = defaultDateTimeFormat.DateTimeFormat;
                }
                Thread.CurrentThread.CurrentUICulture = currentInfo;
                Thread.CurrentThread.CurrentCulture = currentInfo;



        }
    }
}
